//
// Created by xili on 2024/8/8 20:38.
// Go big or go home.
//
#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;

    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode *trainingPlan(ListNode *head, int cnt) {
        //快慢指针，快指针先走cnt步，当快指针到链表尾是，慢指针执行倒数第cnt个元素
        ListNode *slow = head;
        ListNode *fast = head;
        while (cnt--) {
            fast = fast->next;
        }
        while (fast) {
            slow = slow->next;
            fast = fast->next;
        }
        return slow;
    }
};